<form class="area" method="post" style="padding-bottom:40px;">
    <dl class="optBox mt20">
        <dt class="opt"><label class="lb" for="">角色名称</label></dt>
        <dd class="opCon">
            <input type="text" name="name" id="name" style="width: 300px" class="txt" placeholder="请输入名称" value="">
            <p class="tip"></p>
        </dd>
    </dl>
    <dl class="optBox mt20">
        <dt class="opt"><label class="lb" for="">角色描述</label></dt>
        <dd class="opCon">
            <textarea class="txt" id="role" style="height: 200px;width: 300px"  placeholder="请输入角色名称"></textarea>
            <p class="tip"></p>
        </dd>
    </dl>

    <p class="mt20 tc"><input type="button" style="width: 100px; height:30px;" value="提交"   id="btnsubmit"  /> <input type="button" style="width: 100px; height:30px;"  value="返回"  class="btn-back"  /></p>
</form>

<input type="hidden" value="{{url("usermanage/add")}}" id="clicksaveRole">


<link rel="stylesheet" type="text/css" href="{{constant('MANAGE_JS_PATH')}}webuploader-0.1.5/webuploader.css">

<script type="text/javascript" src="{{constant('MANAGE_JS_PATH')}}webuploader-0.1.5/webuploader.nolog.js"></script>

<script type="text/javascript">
/**
 * 保存用户信息Ajax
 * @param name
 * @param role
 */
function ajaxSave(name, role) {
    var url = $("#clicksaveRole").val();
    var data = {
        "name": name,
        "role": role,
    }
    var successFunction = function (res) {
        if (res.status == 200) {
            alert("保存成功");
            window.location.href = "{{url('usermanage/index')}}";
        } else if (res.status == -1) {
            alert(res.info);
        }
    }

    var errorFunction = function (res) {
        alert("保存失败");
    }
    $.ajax({
        url: url,
        data: data,
        type: "post",
        error: errorFunction,
        success: successFunction
    });
}
/**
 * 点击保存后的判断
 * @param name
 * @param role
 */
var clicksaveRole = function () {
    var name = document.getElementById("name").value;
    var role = document.getElementById("role").value;
    if (name == "") {
        $.msgbox("请输入名称");
        return false;
    }
    if (role == "") {
        $.msgbox("请输入角色名称");
        return false;
    }

    $.msgbox({
        height: 120,
        content: {type: 'confirm', content: '确定要提交吗？'},
        onClose: function (result) {
            if (result) {
                ajaxSave(name, role);
            }
        }
    });

}

$(window).load(function () {
    $("#btnsubmit").bind('click', clicksaveRole);
});

</script>
